


<!DOCTYPE html>
<html id="htmlId">
<head>
  <title>Coverage Report > DupAlgorithmTemplate</title>
  <style type="text/css">
    @import "../../css/coverage.css";
    @import "../../css/idea.min.css";
  </style>
  <script type="text/javascript" src="../../js/highlight.min.js"></script>
  <script type="text/javascript" src="../../js/highlightjs-line-numbers.min.js"></script>
</head>

<body>
<div class="content">
<div class="breadCrumbs">
Current scope:     <a href="../../index.html">all classes</a>
    <span class="separator">|</span>
    <a href="../index.html">com.it.alg</a>
</div>

<h1>Coverage Summary for Class: DupAlgorithmTemplate (com.it.alg)</h1>

<table class="coverageStats">

<tr>
  <th class="name">Class</th>
<th class="coverageStat 
">
  Method, %
</th>
<th class="coverageStat 
">
  Line, %
</th>
</tr>
<tr>
  <td class="name">DupAlgorithmTemplate</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (7/7)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    97.6%
  </span>
  <span class="absValue">
    (41/42)
  </span>
</td>
</tr>
  <tr>
    <td class="name">DupAlgorithmTemplate$Conf</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (2/2)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (9/9)
  </span>
</td>
  </tr>
<tr>
  <td class="name"><strong>Total</strong></td>
<td class="coverageStat">
  <span class="percent">
    100%
  </span>
  <span class="absValue">
    (9/9)
  </span>
</td>
<td class="coverageStat">
  <span class="percent">
    98%
  </span>
  <span class="absValue">
    (50/51)
  </span>
</td>
</tr>
</table>

<br/>
<br/>


<pre>
<code class="sourceCode" id="sourceCode">&nbsp;package com.it.alg;
&nbsp;
&nbsp;import java.io.PrintStream;
&nbsp;
&nbsp;import com.it.io.IOSequence;
&nbsp;import com.it.io.IOSequenceFactory;
&nbsp;
&nbsp;public abstract class DupAlgorithmTemplate implements DupAlgorithm {
&nbsp;	
&nbsp;	protected Conf conf;
&nbsp;	
<b class="fc">&nbsp;	public DupAlgorithmTemplate(Conf conf) {</b>
<b class="fc">&nbsp;		this.conf = conf;</b>
&nbsp;	}
&nbsp;	
&nbsp;	@Override
&nbsp;	public final &lt;S, E&gt; S execute(IOSequenceFactory&lt;S, E&gt; ioSequenceFactory, S input) {
<b class="fc">&nbsp;		IOSequence&lt;S, E&gt; ioSequence = ioSequenceFactory.getIOSequence();</b>
<b class="fc">&nbsp;		ioSequence.initInput(input);</b>
<b class="fc">&nbsp;		var stack = new Stack&lt;S, E&gt;();</b>
<b class="fc">&nbsp;		while (ioSequence.hasInput()) {</b>
<b class="fc">&nbsp;			E value = ioSequence.input();</b>
<b class="fc">&nbsp;			stack.add(value);</b>
<b class="fc">&nbsp;		}</b>
<b class="fc">&nbsp;		conf.out.println(&quot;Input: &quot; + stack.nodesToString(conf.separator));</b>
<b class="fc">&nbsp;		conf.out.println(&quot;Output:&quot;);</b>
<b class="fc">&nbsp;		while (!stack.isAllPushed()) {</b>
<b class="fc">&nbsp;			push(ioSequenceFactory, stack);</b>
&nbsp;		}
&nbsp;		
<b class="fc">&nbsp;		ioSequence.initOutput(stack.size());</b>
<b class="fc">&nbsp;		for (E value : stack) {</b>
<b class="fc">&nbsp;			ioSequence.output(value);</b>
<b class="fc">&nbsp;		}</b>
<b class="fc">&nbsp;		return ioSequence.finish();</b>
&nbsp;	}
&nbsp;
&nbsp;	private &lt;E, S&gt; void elimicateIfNeed(IOSequenceFactory&lt;S, E&gt; ioSequenceFactory, Stack&lt;S, E&gt; stack, NodeInfo&lt;E&gt; pushedNode) {
<b class="fc">&nbsp;		int repeatCount = pushedNode.getRepeatCount();</b>
<b class="fc">&nbsp;		if (repeatCount == conf.repeatNum) {</b>
<b class="fc">&nbsp;			for (int i = 0; i &lt; conf.repeatNum; i++) {</b>
<b class="fc">&nbsp;				pop(ioSequenceFactory, stack);</b>
&nbsp;			}
<b class="fc">&nbsp;			replace(ioSequenceFactory, repeatCount, pushedNode.getValue(), stack);</b>
<b class="fc">&nbsp;			printStepResult(ioSequenceFactory, repeatCount, pushedNode.getValue(), stack);</b>
&nbsp;		}
&nbsp;	}
&nbsp;
&nbsp;	protected abstract &lt;S, E&gt; void replace(IOSequenceFactory&lt;S, E&gt; ioSequenceFactory, int repeatCount, E value, Stack&lt;S, E&gt; stack);
&nbsp;
&nbsp;	protected abstract &lt;S, E&gt; String getStepRemark(IOSequenceFactory&lt;S, E&gt; ioSequenceFactory, int repeatCount, E value, Stack&lt;S, E&gt; stack, String separator);
&nbsp;	
&nbsp;	protected final &lt;S, E&gt; NodeInfo&lt;E&gt; push(IOSequenceFactory&lt;S, E&gt; ioSequenceFactory, Stack&lt;S, E&gt; stack) {
<b class="fc">&nbsp;		NodeInfo&lt;E&gt; pushedNode = stack.push();</b>
<b class="fc">&nbsp;		if (conf.needStackChange) {</b>
<b class="fc">&nbsp;			conf.out.println(&quot;push:&quot; + pushedNode.getValue());</b>
&nbsp;		}
<b class="fc">&nbsp;		elimicateIfNeed(ioSequenceFactory, stack, pushedNode);</b>
<b class="fc">&nbsp;		return pushedNode;</b>
&nbsp;	}
&nbsp;	
&nbsp;	protected final &lt;S, E&gt; NodeInfo&lt;E&gt; push(IOSequenceFactory&lt;S, E&gt; ioSequenceFactory, Stack&lt;S, E&gt; stack, E value) {
<b class="fc">&nbsp;		NodeInfo&lt;E&gt; pushedNode = stack.push(value);</b>
<b class="fc">&nbsp;		if (conf.needStackChange) {</b>
<b class="nc">&nbsp;			conf.out.println(&quot;push:&quot; + pushedNode.getValue());</b>
&nbsp;		}
<b class="fc">&nbsp;		elimicateIfNeed(ioSequenceFactory, stack, pushedNode);</b>
<b class="fc">&nbsp;		return pushedNode;</b>
&nbsp;	}
&nbsp;	
&nbsp;	protected final &lt;E, S&gt; void pop(IOSequenceFactory&lt;S, E&gt; ioSequenceFactory, Stack&lt;S, E&gt; stack) {
<b class="fc">&nbsp;		NodeInfo&lt;E&gt; popedNode = stack.pop();</b>
<b class="fc">&nbsp;		if (conf.needStackChange) {</b>
<b class="fc">&nbsp;			conf.out.println(&quot;pop:&quot; + popedNode.getValue());</b>
&nbsp;		}
&nbsp;	}
&nbsp;	
&nbsp;	protected &lt;S, E&gt; void printStepResult(IOSequenceFactory&lt;S, E&gt; ioSequenceFactory, int repeatCount, E value, Stack&lt;S, E&gt; stack) {
<b class="fc">&nbsp;		if (conf.needStepResult) {</b>
<b class="fc">&nbsp;			String stepRemark = this.getStepRemark(ioSequenceFactory, repeatCount, value, stack, conf.separator);</b>
<b class="fc">&nbsp;			if (stepRemark != null &amp;&amp; stepRemark.length() != 0) {</b>
<b class="fc">&nbsp;				conf.out.println(&quot;-&gt; &quot; + stack.nodesToString(conf.separator) + &quot;, &quot; + stepRemark);</b>
&nbsp;			} else {
<b class="fc">&nbsp;				conf.out.println(&quot;-&gt; &quot; + stack.nodesToString(conf.separator));</b>
&nbsp;			}
&nbsp;		}
&nbsp;	}
&nbsp;	
&nbsp;	public static abstract class Conf {
&nbsp;		int repeatNum;
&nbsp;		boolean needStepResult;
&nbsp;		boolean needStackChange;
&nbsp;		PrintStream out;
&nbsp;		String separator;
&nbsp;		public Conf() {
<b class="fc">&nbsp;			this(3, true, false, System.out, &quot;&quot;);</b>
&nbsp;		}
<b class="fc">&nbsp;		public Conf(int repeatNum, boolean needStepResult, boolean needStackChange, PrintStream out, String separator) {</b>
<b class="fc">&nbsp;			if (repeatNum &lt;= 2) {</b>
<b class="fc">&nbsp;				throw new IllegalArgumentException(&quot;repeat number must be grater than 1&quot;);</b>
&nbsp;			}
<b class="fc">&nbsp;			this.repeatNum = repeatNum;</b>
<b class="fc">&nbsp;			this.needStepResult = needStepResult;</b>
<b class="fc">&nbsp;			this.needStackChange = needStackChange;</b>
<b class="fc">&nbsp;			this.out = out;</b>
<b class="fc">&nbsp;			this.separator = separator;</b>
&nbsp;		}
&nbsp;	}
&nbsp;}
</code>
</pre>
</div>

<script type="text/javascript">
(function() {
    var msie = false, msie9 = false;
    /*@cc_on
      msie = true;
      @if (@_jscript_version >= 9)
        msie9 = true;
      @end
    @*/

    if (!msie || msie && msie9) {
      hljs.highlightAll()
      hljs.initLineNumbersOnLoad();
    }
})();
</script>

<div class="footer">
    
    <div style="float:right;">generated on 2023-07-04 12:48</div>
</div>
</body>
</html>
